package com.cyh.core.framework.config;

import java.util.concurrent.Executors;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

/**
 * @Author: yanhang_chen
 * @Date: 2020/9/8 15:51
 */
@Configuration
//定时任务调用一个线程池中的线程。
public class ScheduleConfig implements SchedulingConfigurer {

    @Value("${cyh.constant.ThreadPool}")
    Integer poolSize;

    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        //参数传入一个size为10的线程池
        poolSize = poolSize==null?10:poolSize;
        scheduledTaskRegistrar.setScheduler(Executors.newScheduledThreadPool(poolSize));
    }
}
